import React from 'react';
import {Column} from '@ant-design/charts';


interface DataItem {
    progress: number;
    count: number;
    text?: string; // 新增 text 属性
}

interface ProgressAnalysisProps {
    progressData: {
        id: number;
        progress: number;
        score: number | null;
        completionTime: string | null;
        easyType: number | null;
        remark: string | null;
        workId: number;
    }[];
}

const ProgressAnalysis: React.FC<ProgressAnalysisProps> = ({progressData}) => {

    const progressEnum = [
        {id: 0, status: "processing", text: "进行中"},
        {id: 1, status: "processing", text: "未开始"},
        {id: 2, status: "success", text: "已提交"},
        {id: 3, status: "error", text: "已过期"},
    ];

    const data: DataItem[] = [
        {progress: 0, count: 0, text: "进行中"},
        {progress: 1, count: 0, text: "未开始"},
        {progress: 2, count: 0, text: "已提交"},
        {progress: 3, count: 0, text: "已过期"},
        {progress: 4, count: 0, text: "已过期"},
        {progress: 5, count: 0, text: "已过期"},
    ];
    progressData.forEach((item) => {
        const index = data.findIndex((d) => d.progress === item.progress);
        if (index >= 0) {
            data[index].count += 1;
            data[index].text = (progressEnum.find(e => e.id === item.progress) || {}).text || '';
        }
    });

    // @ts-ignore
    // @ts-ignore
    return (
        <Column
            data={data}
            xField="text"
            yField="count"
            label={{
                formatter: (item) => item.count,
            }}
        />
    );
};

export default ProgressAnalysis;